from collections import namedtuple
from enum import Enum, unique

ota = namedtuple('ota', 'name id')  # ota 定义 id

sp_map = namedtuple('sp_map', 'ota ota_spot_id ext')  # ota平台景区id

"""
ota的id定义
"""


@unique
class OtaCode(Enum):
    HUIQULX = ota('惠趣旅行', 10000)
    MAFENGWO = ota('马蜂窝', 10001)  # 不需要爬取
    CTRIP = ota('携程', 10002)
    FLIGGY = ota('飞猪', 10003)  # 不需要爬
    MEITUAN = ota('美团', 10004)
    LVMAMA = ota('驴妈妈', 10005)
    QUNAR = ota('去哪儿', 10006)
    LY = ota('同程', 10007)
    JD = ota('京东', 10008)


"""
各个景区在每个ota的id映射
"""


@unique
class OtaSpotIdMap(Enum):
    # 石燕湖
    SHI_YAN_HU = [sp_map(OtaCode.HUIQULX, 10001, 0),
                  sp_map(OtaCode.MAFENGWO, 339, 0),
                  sp_map(OtaCode.MEITUAN, 1515791, 0),
                  sp_map(OtaCode.LVMAMA, 100025, 0),
                  sp_map(OtaCode.LY, 9513, 0),
                  sp_map(OtaCode.CTRIP, 62931, 0),
                  sp_map(OtaCode.QUNAR, 706176810, 0),
                  sp_map(OtaCode.FLIGGY, 11481, 0),
                  ]

    # 石牛寨
    SHI_NIU_ZHAI = [sp_map(OtaCode.HUIQULX, 10002, 0),
                    sp_map(OtaCode.MAFENGWO, 5427075, 0),
                    sp_map(OtaCode.MEITUAN, 30067, 0),
                    sp_map(OtaCode.LVMAMA, 103113, 0),
                    sp_map(OtaCode.LY, 25196, 0),
                    sp_map(OtaCode.CTRIP, 127339, 0),
                    sp_map(OtaCode.QUNAR, 1915618311, 0),
                    sp_map(OtaCode.FLIGGY, 33966, 0)
                    ]
    # 益阳嘉年华
    YI_YANG_JIA_NIAN_HUA = [
        sp_map(OtaCode.HUIQULX, 10003, 0),
        sp_map(OtaCode.MAFENGWO, 34944996, 0),
        sp_map(OtaCode.MEITUAN, 179283431, 0),
        sp_map(OtaCode.LVMAMA, 11367356, 0),
        sp_map(OtaCode.CTRIP, 4741361, 0),
        sp_map(OtaCode.QUNAR, 2877753081, 0),
    ]
    # 花田溪谷
    HUA_TIAN_XI_GU = [
        sp_map(OtaCode.HUIQULX, 10004, 0),
        sp_map(OtaCode.MAFENGWO, 71460244, 0),
        sp_map(OtaCode.MEITUAN, 188085997, 0),
        sp_map(OtaCode.CTRIP, 5060343, 0),
        sp_map(OtaCode.QUNAR, 2554926827, 0),
        sp_map(OtaCode.FLIGGY, 140975087, 0),
    ]
    # 东浒寨
    DONG_HU_ZHAI = [
        sp_map(OtaCode.HUIQULX, 10005, 0),
        sp_map(OtaCode.MAFENGWO, 33665644, 0),
        sp_map(OtaCode.MEITUAN, 115915971, 0),
        sp_map(OtaCode.LVMAMA, 10829578, 0),
        sp_map(OtaCode.CTRIP, 1979030, 0),
        sp_map(OtaCode.LY, 229768, 0),
        sp_map(OtaCode.QUNAR, 225118749, 0),
        sp_map(OtaCode.FLIGGY, 32659156, 0),
    ]
    # 马仁奇峰
    MA_REN_QI_FENG = [
        sp_map(OtaCode.HUIQULX, 10006, 0),
        sp_map(OtaCode.MAFENGWO, 5436442, 0),
        sp_map(OtaCode.MEITUAN, 1451152, 0),
        sp_map(OtaCode.LVMAMA, 103177, 0),
        sp_map(OtaCode.CTRIP, 65169, 0),
        sp_map(OtaCode.LY, 5808, 0),
        sp_map(OtaCode.QUNAR, 3821817759, 0),
        sp_map(OtaCode.FLIGGY, 103590, 0),
    ]
    # 大茅山
    DA_MAO_SHAN = [
        sp_map(OtaCode.HUIQULX, 10007, 0),
        sp_map(OtaCode.MAFENGWO, 7689642, 0),
        sp_map(OtaCode.MEITUAN, 41614694, 0),
        sp_map(OtaCode.CTRIP, 1493248, 0),
        sp_map(OtaCode.QUNAR, 420237024, 0),
        sp_map(OtaCode.LY, 231854, 0),
        sp_map(OtaCode.FLIGGY, 61484, 0),
    ]
    # 九龙江
    JIU_LONG_JIANG = [
        sp_map(OtaCode.HUIQULX, 10008, 0),
        sp_map(OtaCode.MEITUAN, 41164719, 0),
        sp_map(OtaCode.LVMAMA, 160416, 0),
        sp_map(OtaCode.CTRIP, 140900, 0),
        sp_map(OtaCode.LY, 29283, 0),
        sp_map(OtaCode.QUNAR, 4123349957, 0),
        sp_map(OtaCode.FLIGGY, 191470, 0),
    ]
    # 天空之城
    TIAN_KONG_ZHI_CHENG = [
        sp_map(OtaCode.HUIQULX, 10009, 0),
        sp_map(OtaCode.MEITUAN, 182573099, 0),
        sp_map(OtaCode.LVMAMA, 11945662, 0),
        sp_map(OtaCode.CTRIP, 5058354, 0),
        sp_map(OtaCode.FLIGGY, 140626417, 0),
    ]
    # 连云山
    LIAN_YUN_SHAN = [
        sp_map(OtaCode.HUIQULX, 10010, 0),
        sp_map(OtaCode.MAFENGWO, 33673148, 0),
        sp_map(OtaCode.MEITUAN, 5464367, 0),
        sp_map(OtaCode.LVMAMA, 102525, 0),
        sp_map(OtaCode.CTRIP, 1411376, 0),
    ]
    # 侠天下
    XIA_TIAN_XIA = [
        sp_map(OtaCode.HUIQULX, 10011, 0),
        sp_map(OtaCode.MAFENGWO, 24960734, 0),
        sp_map(OtaCode.MEITUAN, 51575391, 0),
        sp_map(OtaCode.LVMAMA, 10650528, 0),
        sp_map(OtaCode.CTRIP, 1415157, 0),
        sp_map(OtaCode.LY, 182563, 0),
        sp_map(OtaCode.QUNAR, 2333288470, 0),
        sp_map(OtaCode.FLIGGY, 17165564, 0),
    ]
    # 三翁花园
    SAN_FENG_HUA_YUAN = [
        sp_map(OtaCode.HUIQULX, 10012, 0),
        sp_map(OtaCode.MAFENGWO, 70048608, 0),
        sp_map(OtaCode.MEITUAN, 158907227, 0),
        sp_map(OtaCode.LVMAMA, 12210014, 0),
        sp_map(OtaCode.LY, 672767, 0),
        sp_map(OtaCode.CTRIP, 3989530, 0),
        sp_map(OtaCode.QUNAR, 3333064220, 0),
        sp_map(OtaCode.FLIGGY, 33559796, 0),
    ]
    # 乌金山
    WU_JIN_SHAN = [
        sp_map(OtaCode.HUIQULX, 10013, 0),
        sp_map(OtaCode.MAFENGWO, 964195, 0),
        sp_map(OtaCode.MEITUAN, 2498352, 0),
        sp_map(OtaCode.LVMAMA, 162027, 0),
        sp_map(OtaCode.CTRIP, 3264963, 0),
    ]
    # 恺之峰
    KAI_ZHI_FENG = [
        sp_map(OtaCode.CTRIP, 1410449, 0),
        sp_map(OtaCode.QUNAR, 63919496, 0),
        sp_map(OtaCode.LY, 190966, 0),
    ]

    # 上海迪斯尼
    DI_SI_NI = [
        sp_map(OtaCode.FLIGGY, 15968, 0),
    ]

    @classmethod
    def get_ota_spot_id(cls, spot_name: str, ota_code: OtaCode) -> int:
        if spot_name not in cls.__members__:
            raise Exception('景区名称未定义！')
        for map_item in cls[spot_name].value:
            if map_item.ota == ota_code:
                return map_item.ota_spot_id

    @classmethod
    def get_ota_spot_list(cls, ota_code: OtaCode) -> list:
        return [item.ota_spot_id for _, member in cls.__members__.items() for item in member.value if
                item.ota == ota_code]

    @classmethod
    def get_ota_spot(cls, ota_code: OtaCode) -> list:
        return [item for _, member in cls.__members__.items() for item in member.value if
                item.ota == ota_code]
